-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Fix: Comments number is wrong - Core ticket - 36409 #9277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Fix: Comments number is wrong - Core ticket - 36409 #9277
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
| /** | ||
| * Get all the comments related to the post ID. | ||
| */ | ||
| $comments = $wpdb->get_results( $wpdb->prepare( "SELECT comment_ID, comment_parent, comment_approved FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach could be too expensive if there are a large number of comments. Have you tested this with, for example, 1ok unapproved comments? It would be good to understand the performance impact at that scale.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have not tested this scenario with that number of comments, I will check for the same. Also, I am not sure if we have a better solution than this? because everything is in one table like the replationships as well, SQL query would be also expensive in this case and would not cover all the deeply nested comments.
We can also do some caching with array mechanism to skip the parents that are already checked in the current approach?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @mukeshpanchal27, I tested with 10K comments and it looks like it is not performant heavy, I have recorder the screencast below with the changes in PR and it looks good with not performant heavy in counting the comments, ofCourse it would take time when the actual comments are being rendered on the page.
Screen.Recording.2025-07-17.at.2.39.26.PM.mov
Thank You,
|
Can we get some phpunit tests here to show this fixes the bug and to prevent regressions? |
Hi @mindctrl, I have added the test cases for the updated scenario. Thank You, |
|
Can we mention ticket number in unit test? |
|
@hbhalodia, Since the failure occurred in the CI, I merged the latest trunk into this pull request. |
Trac ticket: https://core.trac.wordpress.org/ticket/36409
Fixes
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.